'''
@author: pnuzhnyi
'''

from gear.repository import gear_repository
from surfers.repository import surfer_repository

def buy_item(item,surfer):
    if item.price > surfer.stats["cash"]: return False
    if item.units <= 0: return False
    
    surferStats = surfer.stats
    surferStats["cash"] = surferStats["cash"] - item.price 
    surfer.stats = surferStats
    
    surfer_repository().update_surfer(surfer)
    gear_repository().add_gear_for_user(surfer.fbook_id, item.id)
    
    return True
